local MODNAME, DailyIntake  = ...

-------------------------------------------------------------------------------
-- Localized Lua globals
-------------------------------------------------------------------------------

local _G = getfenv(0)

local abs		= _G.abs
local print		= _G.print
local sqrt		= _G.sqrt

-------------------------------------------------------------------------------
-- AddOn namespace
-------------------------------------------------------------------------------

-- basic addon framework
assert(DailyIntake,"Addon table is nil")
_G[MODNAME] = DailyIntake

DailyIntake.Settings = {};
DailyIntake.Localization = {};

-- addon features
DailyIntake.QuestItems = {};
DailyIntake.Alchemist = {};

-- Returns localized version of text if found, otherwise the text itself is returned.
local function Localize(text)
    local translateFunction = DailyIntake.Localization[text];
    if translateFunction then
        return translateFunction();
    else
        return text;
    end;
end;

-- Does all the initialization routines. Is called after ADDON_LOADED event.
local function Initalize()
    DailyIntake.QuestItems.Initialize();
    --DailyIntake.Alchemist.Initialize();
end;

-- expose public methods
DailyIntake.Localize = Localize;

-- wire up events
local frame = CreateFrame("Frame");
local events = {};

function events:ADDON_LOADED(addonName)
    if addonName == "DailyIntake" then
        Initalize();
    end;
end;

frame:SetScript("OnEvent", function(self, event, ...)
    events[event](self, ...); -- call one of the functions above
end);

for eventName, _ in pairs(events) do
    frame:RegisterEvent(eventName); -- Register all events for which handlers have been defined
end

DailyIntake.X = 0;
DailyIntake.Y = 0;
function DailyIntake.MemorizePosition()
    DailyIntake.X, DailyIntake.Y = _G.GetPlayerMapPosition("player");
    print(DailyIntake.X, DailyIntake.Y);
end;

function DailyIntake.GetDistance()
    local x, y = _G.GetPlayerMapPosition("player");
    return sqrt(abs(DailyIntake.X - x)^2 + abs(DailyIntake.Y - y)^2);
end;
